<template>
  <a-table :columns="columns" :data-source="page.list" :pagination="pagination" @change="handleTableChange">
    <template #user_id="{ text }">
      <span>
        {{ text }}
      </span>
    </template>

    <template #user_name="{ text }">
      <span>
        {{ text }}
      </span>
    </template>
    <template #user_age="{ text }">
      <span>
        <mail-outlined/>
        {{ text }}
      </span>
    </template>
    <template #email="{ text }">
      <span>
        <history-outlined/>
        {{ text }}
      </span>
    </template>

    <template #action="{ record }">
      <el-link type="warning" @click="getUser_Id(record),deleteInfo()">删除</el-link>
      <a-divider type="vertical" style="color:blue"/>
      <el-link type="warning" @click="getUser_Id(record), visible2 = true">修改</el-link>
    </template>
  </a-table>

  <!-- 修改咨询师信息 -->

  <el-dialog v-model="visible2" title="修改信息填写" width="30%">
    <a-from>
      <option>修改用户姓名</option>
      <input v-model="value5" type="text" name="user_name1" id="user_name1">
    </a-from>

    <a-from>
      <option>修改用户年龄</option>
      <input v-model="value6" type="text" name="user_age1" id="user_age1">
    </a-from>


    <template #footer>
      <span class="change">
        <el-button @click="deleteInfo(),visible2 = false">取消</el-button>
        <el-button type="change" @click="changeInfo(), visible2 = false">确认</el-button>
      </span>
    </template>
  </el-dialog>


</template>

<script lang="ts" setup>
////////////////////////////////////////////
import {reactive, ref} from "vue";
import {post, setLocalToken} from "@/common";
import {useRouter} from "vue-router";
import {get} from "@/common";
import {message} from "ant-design-vue";
//import {DownloadOutlined} from "";
////////////////////////////////////////////
////////////////////////////////////////////
const visible1 = ref(false);
const visible2 = ref(false);

const value1 = ref("");
const value2 = ref("");
const value3 = ref("");
const value4 = ref("");
const value5 = ref("");
const value6 = ref("");
const value7 = ref("");


const columns = [
  {
    dataIndex: "user_id", //
    title: "序号",
    slots: {
      customRender: "user_id",
    },
  },
  {
    dataIndex: "user_name", //
    title: "姓名",
    slots: {
      customRender: "user_name",
    },
  },
  {
    dataIndex: "user_age", //
    title: "年龄",
    slots: {
      customRender: "user_age",
    },
  },
  {
    dataIndex: "email", //
    title: "邮箱",
    slots: {
      customRender: "email",
    },
  },

  {
    title: "操作",
    key: "action",
    slots: {
      customRender: "action",
    },
  },
];
const page = ref({});
const pagination = reactive({
  current: 1, //当前页
  pageSize: 5, //每页记录数
  total: 0, //总记录数
  pageSizeOptions: ["2", "3", "5", "10", "20", "30", "100"], //每页记录下拉框的选型
  showSizeChanger: true, //是否展示每页记录数下拉框
  showQuickJumper: true, //是否展示快速跳转
  showTotal: (total, range) => {
    //展示总页数等文字说明信息的
    return (
        "共" +
        total +
        "条记录,当前第" +
        pagination.current +
        "页" +
        (range[1] - range[0] + 1) +
        "条记录"
    );
  },
});

const user = reactive({

  role_id: "",
  user_id: "",
  user_name: "",
  user_age: "",
  email: ""
});

const setuser1 = () => {
  user.user_id = value1.value;
  user.user_name = value2.value;
  user.user_age = value3.value;
  user.email = value4.value;
}

const setuser2 = () => {
  user.user_name = value5.value;
  user.user_age = value6.value;
  user.email = value7.value;
}

const getUser_Id = (record) => {
  user.user_id = record.user_id;
}

const insertInfo = () => {
  setuser1();
  post("/security/infoManage/insertInfo", user).then((res) => {
    if (res.success) {
      getPage(1);
    }
  });
};

const changeInfo = () => {
  setuser2();
  post("/security/infoManage/changeInfo", user).then((res) => {
    if (res.success) {
      getPage(1);
    }
  });
};
const deleteInfo = () => {
  post("/security/infoManage/deleteInfo", user).then((res) => {
    if (res.success) {
      getPage(1);
    }
  });
}

const getPage = (pageNum = 1) => {
  user.pageNum = pageNum;
  user.pageSize = pagination.pageSize;
  post("/security/infoManage/getInfo", user).then((res) => {
    page.value = res.data; //将服务端传来的分页数据赋值予page

    //更新分页引擎
    pagination.current = page.value.current;
    pagination.pageSize = page.value.pageSize;
    pagination.total = page.value.total;

    console.log(res.data.list);
  });
};

getPage(1);

const handleTableChange = (pagi, filters, sorter) => {
  pagination.current = pagi.current;
  pagination.pageSize = pagi.pageSize;
  pagination.total = pagi.total;

  getPage(pagination.current);
};

////////////////////////////////////////////
</script>

<style>
</style>